﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxTreeList;

namespace ERB.UserControl.Navigation
{
    public partial class NavControl : System.Web.UI.UserControl
    {
        #region Properties
        ASPxGridView _gv;
        public ASPxGridView gv
        {
            set
            {
                _gv = value;
            }
            get
            {
                return _gv;
            }
        }
        ASPxTreeList _treelist;
        public ASPxTreeList treelist
        {
            set
            {
                _treelist = value;
            }
            get
            {
                return _treelist;
            }
        }
        private string _noderoottext = "";
        public string noderoottext
        {
            get { return _noderoottext; }
            set { _noderoottext = value; }
        }
        private string _noderooturl = "";
        public string noderooturl
        {
            get { return _noderooturl; }
            set { _noderooturl = value; }
        }
        private string _nodecurrenttext = "";
        public string nodecurrenttext
        {
            get { return _nodecurrenttext; }
            set { _nodecurrenttext = value; }
        }
        private string _nodecurrenturl = "";
        public string nodecurrenturl
        {
            get { return _nodecurrenturl; }
            set { _nodecurrenturl = value; }
        }
        private string _addprintscript = "";
        public string addprintscript
        {
            get { return _addprintscript; }
            set { _addprintscript = value; }
        }
        public string _addnewscript = "";
        public string addnewscript
        {
            get { return _addnewscript; }
            set { _addnewscript = value; }
        }
        private string _editscript = "";
        public string editscript
        {
            get { return _editscript; }
            set { _editscript = value; }
        }
        private string _delscript = "";
        public string delscript
        {
            get { return _delscript; }
            set { _delscript = value; }
        }
        public string _savescript = "";
        public string savescript
        {
            get { return _savescript; }
            set { _savescript = value; }
        }
        public string _savenewscript = "";
        public string savenewscript
        {
            get { return _savenewscript; }
            set { _savenewscript = value; }
        }
        public string _closescript = "";
        public string closescript
        {
            get { return _closescript; }
            set { _closescript = value; }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (gv == null && treelist == null)
                {
                    GridNavbar.Visible = false;
                }
                else
                {

                    if (_addprintscript == "")
                        btnPrint.Visible = false;
                    else
                        btnPrint.ClientSideEvents.Click = _addprintscript;

                    if (_addnewscript == "")
                        btnNew.Visible = false;
                    else
                        btnNew.ClientSideEvents.Click = _addnewscript;

                    if (_editscript != "")
                        btnEdit.ClientSideEvents.Click = _editscript;

                    if (treelist == null)
                    {
                        if (_delscript == "True")
                            btnDel.ClientSideEvents.Click = "function(s, e) { checkDel(" + _gv.ClientInstanceName + ");}";
                        else
                            btnDel.Visible = false;
                    }
                    else
                    {
                        if (_delscript == "True")
                            btnDel.ClientSideEvents.Click = "function(s, e) { checkDelTree(" + _treelist.ClientInstanceName + ");}";
                        else
                            btnDel.Visible = false;
                    }
                }
            }
        }

        protected void mnExport_ItemClick(object source, DevExpress.Web.ASPxMenu.MenuItemEventArgs e)
        {
            try
            {
                if (e.Item.Name != "")
                {
                    if (treelist == null)
                    {

                        switch (e.Item.Name)
                        {
                            case "PDF":
                                baseGVExport.WritePdfToResponse();
                                break;
                            case "DOC":
                                baseGVExport.WriteRtfToResponse();
                                break;
                            case "XLS":
                                baseGVExport.WriteXlsToResponse();
                                break;
                            case "CVS":
                                baseGVExport.WriteCsvToResponse();
                                break;
                            case "XLS2007":
                                baseGVExport.WriteXlsxToResponse();
                                break;
                            default:
                                baseGVExport.WriteCsvToResponse();
                                break;
                        }
                    }
                    else
                    {

                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}